<?php

// +----------------------------------------------------------------------
// | Shop-Demo for ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2022~2023 Anyon <zoujingli@qq.com>
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 免责声明 ( https://thinkadmin.top/disclaimer )
// | 会员免费 ( https://thinkadmin.top/vip-introduce )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\data\controller;

use app\data\model\DataXinSite;
use think\admin\Controller;
use think\admin\helper\QueryHelper;

/**
 * 场次管理
 * Class Cate
 * @package app\data\controller\shop
 */
class Site extends Controller
{

    /**
     * 场次列表管理
     * @auth true
     * @menu true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        DataXinSite::mQuery()->layTable(function () {
            $this->title = "场次列表管理";
        }, function (QueryHelper $query) {
            $query->like('name')->dateBetween('create_at');
        });
    }

    /**
     * 列表数据处理
     * @param array $data
     */
    protected function _index_page_filter(array &$data)
    {
    }

    /**
     * 添加场次
     * @auth true
     */
    public function add()
    {
        DataXinSite::mForm('form');
    }

    /**
     * 编辑场次
     * @auth true
     */
    public function edit()
    {
        DataXinSite::mForm('form');
    }

    /**
     * 表单数据处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _form_filter(array &$data)
    {
        if ($this->request->isGet()) {

        }else{
            if(!isset($data['id'])){$data['addtime'] = date('Y-m-d H:i:s');}
            if(!empty($data['time'])){
                $time = explode(" - ",$data['time']);
                $data['s_time'] = $time[0];
                $data['e_time'] = $time[1];
            }
        }
    }


    /**
     * 修改场次状态
     * @auth true
     */
    public function state()
    {
        DataXinSite::mSave($this->_vali([
            'status.in:0,1'  => '状态值范围异常！',
            'status.require' => '状态值不能为空！',
        ]));
    }

    /**
     * 表单结果处理
     * @param boolean $state
     */
    protected function _form_result(bool $state)
    {
        if ($state) {
            $this->success('操作成功！', 'javascript:history.back()');
        }
    }

    /**
     * 删除场次
     * @auth true
     */
    public function remove()
    {
        DataXinSite::mDelete();
    }
}